// pages/moreList/moreList.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList:['新闻资讯','通知公告','工作动态'],
    activeIndex:0,
    pageSize:1,
    pageNum:6,
    isPull:true,
    keyValue:'',
    status:'',
    workdata:[],
    news:[],
    notice:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this 
    var page = that.data.pageSize
    var key = that.data.keyValue
    var status = that.data.status
    this.getnewsData(page,key,status)
    this.getnoticeData(page,key,status)
    this.getworkData(page,key,status)
  },
  // 新闻资讯
  getnewsData:function(page,key,type){
    var that = this
    var data ={
      page:page,
      limit:that.data.pageNum,
      search:key
    }
    request.get('article/list/2',data,{ noAuth : true}).then(res=>{
      if(type=='search'){
        that.setData({
          news:[]
        })
      }
      if(res.data.length>0){
        that.setData({
          news:that.data.news.concat(res.data)
        })
       }else{
        that.setData({
           isPull:false
         })
       }
    })
  },
  // 通知公告
  getnoticeData:function(page,key,type){
    var that = this
    var data ={
      page:page,
      limit:that.data.pageNum,
      search:key
    }
    request.get('article/list/3',data,{ noAuth : true}).then(res=>{
      if(type=='search'){
        that.setData({
          notice:[]
        })
      }
      if(res.data.length>0){
        that.setData({
          notice:that.data.notice.concat(res.data)
        })
       }else{
        that.setData({
           isPull:false
         })
       }
    })
  },
  //工作状态
  getworkData:function(page,key,type){
    var that = this
    if(type=='search'){
      that.setData({
        workdata:[]
      })
    }
    var data ={
      page:page,
      limit:that.data.pageNum,
      search:key
    }
    request.get('article/list/4',data,{ noAuth : true}).then(res=>{
      if(res.data.length>0){
        that.setData({
          workdata:this.data.workdata.concat(res.data)
        })
       }else{
        that.setData({
           isPull:false
         })
       }
    })
  },
  getIndex:function(e){
    console.log(e)
    this.setData({
      activeIndex:e.detail.index,
      pageSize:1,
      isPull:true
    })
  },
  search_value:function(e){
    var key = e.detail.send_value
    this.setData({
      keyValue:key,
      status:'search',
      pageSize:1,
      isPull:true
    })
    var page = this.data.pageSize
    var type = this.data.activeIndex
    var status = this.data.status
    if(type==0){
      this.getnewsData(page,key,status)
    }else if(type==1){
      this.getnoticeData(page,key,status)
    }else if(type==2){
      this.getworkData(page,key,status)
    }
   },
   details:function(o){
     console.log(o)
     var id = o.currentTarget.dataset.id
    wx.navigateTo({
      url: './datadetails/datadetails?id='+id,
    })
   },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var value = this.data
    if(value.isPull){
      var nextPage = ++value.pageSize
      var key = value.keyValue
       if(value.activeIndex==0){
         this.getnewsData(nextPage,key)
       }else if(value.activeIndex==1){
         this.getnoticeData(nextPage,key)
       }else if(value.activeIndex==2){
         this.getworkData(nextPage,key)
       }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})